package com.hl.sfzy.service;

import com.hl.sfzy.entity.SearchTrendsTeachers;
import com.hl.sfzy.mapper.SearchTrendsTeachersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class SearchTrendsTeachersService {
    @Autowired
    private SearchTrendsTeachersMapper searchTrendsTeachersService;
    public List<SearchTrendsTeachers> searchTrendsTeachersService(String teacherName, String address, String sex, String levelName, String goodAreas) {
        System.out.println(teacherName+"sevice");
        List<Integer> teacherId1=new ArrayList<>();
        List<Integer> teacherId2=new ArrayList<>();
        List<Integer> teacherId3=new ArrayList<>();
        List<SearchTrendsTeachers> teacherList=new ArrayList<>();
        if(teacherName!=null||address!=null||sex!=null){
             teacherId1 = searchTrendsTeachersService.selectInfById(teacherName, address, sex);
            System.out.println(teacherId1+"1111111");
        } else if (goodAreas!=null) {
             teacherId2=searchTrendsTeachersService.selectGoodsById(goodAreas);
             System.out.println(teacherId2+"22222" );
        } else if (levelName!=null) {
             teacherId3=searchTrendsTeachersService.selectLevelById(levelName);
             System.out.println(teacherId3+"333333");
        }
        System.out.println("查到id");
        //将查询到的id集合进行合并
        List<List<Integer>> teacherIds= new ArrayList<>();
        teacherIds.add(teacherId1);
        teacherIds.add(teacherId2);
        teacherIds.add(teacherId3);
        Set<Integer> terSet = new HashSet<>();
        for (List<Integer> list : teacherIds) {
            if (list != null) {
                terSet.addAll(list);
            }
        }

        //将合并后的集合转换为list
        List<Integer> tealist = new ArrayList<>(terSet);
        System.out.println("tealist"+tealist);
        //根据id查询
        for (Integer id : tealist) {
            SearchTrendsTeachers teacher = searchTrendsTeachersService.selectTeacherById(id);
            System.out.println(teacher);
            teacherList.add(teacher);
        }
        return teacherList;

    }


}
